import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:f_demo/bloc/index.dart';
import 'package:f_demo/res/colors.dart';

class ThemeBloc extends Bloc<ThemeEvent, ThemeState> {
  @override
  get initialState =>
      ThemeState(brightness: Brightness.light, color: Colours.gray_33);

  @override
  Stream<ThemeState> mapEventToState(ThemeEvent event) async* {
    if (event is UpdateBrightnessEvent) {
      yield ThemeState(
          brightness: event.brightness ? Brightness.dark : Brightness.light,
          color: currentState.color);
    } else if (event is UpdateThemeEvent) {
      yield ThemeState(
          brightness: currentState.brightness,
          color: themeColorMap[event.color]);
    }
  }
}
